package com.ruoyi.web.controller.psi;

import cn.hutool.crypto.digest.MD5;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.domain.ApproveLog;
import com.ruoyi.req.ApproveLogReq;
import com.ruoyi.service.ApproveLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * lhp
 * 2023/9/11
 */
@RestController
@RequestMapping("/approve")
public class ApproveLogController extends BaseController {
    @Autowired
    private ApproveLogService approveLogService;

    @Log(title = "提交出库审核", businessType = BusinessType.CLEAN)
    @PreAuthorize("@ss.hasPermi('psi:outstore:add')")
    @PostMapping("/out")
    public AjaxResult out(@RequestBody List<ApproveLogReq> approveLogReqs){
        AjaxResult ajaxResult = approveLogService.out(approveLogReqs);
        return ajaxResult;
    }

    @Log(title = "库存数据", businessType = BusinessType.OTHER)
    @PreAuthorize("@ss.hasPermi('psi:store:query')")
    @RequestMapping("/list")
    public TableDataInfo list( @RequestBody ApproveLogReq approveLogReq){
        startPage();
        List<ApproveLog> list = approveLogService.getList(approveLogReq);
        return getDataTable(list);
    }

    @Log(title = "同意", businessType = BusinessType.OTHER)
    @PreAuthorize("@ss.hasPermi('psi:approvelog:audit')")
    @PostMapping("/agree")
    public AjaxResult agree(@RequestBody List<ApproveLog> approveLogList){
        AjaxResult ajaxResult = approveLogService.agree(approveLogList);
        return ajaxResult;
    }

    @Log(title = "拒绝", businessType = BusinessType.OTHER)
    @PreAuthorize("@ss.hasPermi('psi:approvelog:refuse')")
    @PostMapping("/refuse")
    public AjaxResult refuse(@RequestBody ApproveLogReq approveLogReq){
        AjaxResult ajaxResult = approveLogService.refuse(approveLogReq);
        return ajaxResult;
    }


}
